﻿using System;
using System.Text;
using System.Web;
using System.Web.Mvc;

namespace SRF.UI.View
{
    public class ExceptionResult : ActionResult
    {
        public ExceptionResult()
        { }
        public ExceptionResult(string message)
        {
            this.Message = message;
        }
        public ExceptionResult(string message, int statusCode)
        {
            this.Message = message;
            this.StatusCode = statusCode;
        }

        public string Message
        {
            get;
            set;
        }

        public int StatusCode
        {
            get;
            set;
        }

        public string ContentType
        {
            get;
            set;
        }

        public override void ExecuteResult(ControllerContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            HttpResponseBase response = context.HttpContext.Response;

            if (!String.IsNullOrEmpty(ContentType))
            {
                response.ContentType = ContentType;
            }
            if (StatusCode > 0)
            {
                response.StatusCode = StatusCode;
            }
            if (Message != null)
            {
                response.Write(Message);
            }
        }
    }
}